/**
 * Virtual Machine (Common Runtime Environment)
 **/

#include "function.h"

namespace Core {
	/**
	 * Wrapper for native value types in the runtime.
	 **/
	typedef union {
		int Integer;
		float Float;

		tHandle Object;
		// Raw value types - used with native compiled code
		Object * RawPtr;
		Functor * RawFunctor;
	} tValue;

	/**
	 * A packed instruction.
	 **/
	struct Instruction {
		enum Opcode {
			NOP = 0,
			COPY, //< Copy register
			DEREF, //< Dereference object
			QUERY, //< Lookup
			
		};
		enum OperandType {
			NONE = 0, //< No operand
			IMED, //< Intermediate value
			REG, //< Register ID
			OBJECT, //< Handle to an object
		};

		Opcode opcode : 16;
		OperandType operandAType : 8;
		OperandType operandBType : 8;
	};

	/** 
	 * The VM execution context
	 **/
	struct Context {
		struct LocalVariable {
			StringPool::Entry name;
			tValue value;
		};

		/// Special register for holding operation return values.
		tValue returnReg;
		std::vector<LocalVariable> zLocalVars;
	};

	class VirtualMachine {
		
	};
};
